import { useUserStore } from "@/stores/user";
import axios from "axios";

const httpInstance = axios.create({
  baseURL: "http://pcapi-xiaotuxian-front-devtest.itheima.net",
  timeout: 10000,
})
// http://pcapi-xiaotuxian-front-devtest.itheima.net
//拦截器
httpInstance.interceptors.request.use(config => {
  const userStore = useUserStore()
  const token = userStore.userInfo.token
  if (token) {
    config.headers.Authorization = `Bearer ${token}`
  }
  return config
}, e => {
  return Promise.reject(e)
})
httpInstance.interceptors.response.use(res => {
  return res.data
}, e => {
  return Promise.reject(e)
})

export default httpInstance;